﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataLib.Accounts.Bus;
using System.Data;

namespace DataLib.Accounts
{
    public partial class UserAdminList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ListItem item = new ListItem();
                item.Text = "--请选择--";
                item.Value = "";
                BLL.City bllcity = new BLL.City();
                dropGraphic.DataSource = bllcity.GetList(" flag1 = '01'");
                dropGraphic.DataTextField = "cityname";
                dropGraphic.DataValueField = "cityname";
                dropGraphic.DataBind();
                dropGraphic.Items.Insert(0,item);
 
                bindData();
           }

        }

        protected void bindData()
        {
            User curUser = new User();
            curUser = (User)Session["UserInfo"];
            if (curUser != null)
            {
                hidUserLev.Value = curUser.UserType;
                if (curUser.UserType != "AD")
                {
                    dropGraphic.SelectedValue = curUser.CompanyCity;
                    dropGraphic.Enabled = false;
                   
                }
            }
 
            DataSet ds = new DataSet();
            Bus.User bUser = new Bus.User();
            string CompanyCity = null;
            string TrueName = null;
            if (dropGraphic.SelectedValue != "")
            {
                CompanyCity = dropGraphic.SelectedValue;
            }
            //if (txtTrueName.Text.Trim() != "")
            //{
            //    TrueName = txtTrueName.Text.Trim();
            //}
            reptUser.DataSource = bUser.GetUserList(TrueName,CompanyCity);
            reptUser.DataBind();
        }

        protected void LkbDeleteUser_Click(object sender, EventArgs e)
        {
            LinkButton lb = (LinkButton)sender;
            string userID = lb.CommandArgument;
            Bus.User SelectedUser = new User(int.Parse(userID));

            if (SelectedUser.Delete())
            {
                bindData();
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('用户删除失败，请稍候重试');</script>");
            }

        }

        protected void dropBelong_SelectedIndexChanged(object sender, EventArgs e)
        {
            bindData();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            bindData();
        }

        protected string GetStringLev(string levValue)
        {
            string text = "";
            DataLib.Model.Sys_Library libModel = new DataLib.Model.Sys_Library();
            DataLib.BLL.Sys_Library libBll = new DataLib.BLL.Sys_Library();
            DataTable dt = libBll.GetLibByCate("权限分级");
            foreach (DataRow dr in dt.Rows)
            {
                if (dr["libKey"].ToString() == levValue)
                {
                    text = dr["libValue"].ToString();
                    break;
                }
            }

            return text;
        }
    }
}